package demo1;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-05-19
 * Time:23:31
 */
class Shape{
    //属性...
    public void draw(){
        System.out.println("画图形！");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("♦");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("●");
    }
}
class Triangle extends Shape{
    @Override
    public void draw() {
        System.out.println("▲");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("🌹");
    }
}

public class Test2 {
    public static void drawMap(Shape shape){
        shape.draw();
    }
    public static void main(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Triangle triangle =new Triangle();
        Flower flower = new Flower();
        /*drawMap(rect);
        drawMap(cycle);
        drawMap(triangle);
        drawMap(flower);*/
        Shape[] shapes = {rect,cycle,triangle,flower};
        for (Shape shape:shapes){
            //当前shape引用的对象重写draw方法就调用，没有就调用shape自己的
            shape.draw();
        }
    }
}

